﻿$(function() {
	var UAtransform = null;
	var count = 0;
	var rotateSymbol = document.getElementById("rotate-bg");
	var itIe9 = function() {return $.browser.msie && $.browser.version < 9;}();
	(function UA() {
		var arry = ['-ms-transform', '-moz-transform', '-o-transform', 'transform', '-webkit-transform'];
		for (var i = 0; i < arry.length; i++) {
			if (rotateSymbol.style[arry[i]] != undefined) {
				return UAtransform = arry[i];
			}
		}
	})();
	var rotate = (function() {
		return function(dom, angle) {
			var rad = angle * (Math.PI / 180),
			dx = (1 - Math.cos(Math.PI / 4 + rad) / Math.cos(Math.PI / 4)) * 240,
			dy = (1 - Math.sin(Math.PI / 4 + rad) / Math.cos(Math.PI / 4)) * 240,
			m11 = Math.cos(rad),
			m12 = -1 * Math.sin(rad),
			m21 = Math.sin(rad),
			m22 = m11;
			if (itIe9) {
				dom.style.filter = 'progid:DXImageTransform.Microsoft.Matrix(Dx=' + dx + ',Dy=' + dy + ',M11=' + m11 + ',M12=' + m12 + ',M21=' + m21 + ',M22=' + m22 + ',SizingMethod="clip to original")';
			} else {
				dom.style[UAtransform] = 'rotate(' + angle + 'deg)'
			}
		};
	})();
	function tips() {
		var intros = $('.kv-list-box'),
		introIcons = $('.intro-ico'),
		introLength = intros.length,
		count = 0;
		var active = null;
		var introLoop = null;
		function introFade() {
			var o = intros.eq(count);
			var i = introIcons.eq(count);
			if (!active) {
				o.fadeIn('slow', 'linear');
				i.addClass('img-zoom');
				active = o;
				++count;
			} else {
				active.fadeOut('slow', 'linear');
				active.prev().removeClass('img-zoom');
				o.fadeIn('slow', 'linear');
				i.addClass('img-zoom');
				active = o;
				++count;
			}
		};
		function startAnimation() {
			introLoop = setInterval(function() {
				if (count == introLength) {
					count = 0
				};
				introFade();
			},
			3000)
		};
		function stopAnimation() {
			clearInterval(introLoop);
			intros.hide();
			introIcons.removeClass('img-zoom');

		};
		startAnimation();
		introIcons.on('mouseover',function() {
			stopAnimation();
			$(this).next().fadeIn('slow');
		});
		introIcons.on('mouseout',function() {
			count = introIcons.index($(this)) + 1;
			startAnimation();
			$(this).next().fadeOut('slow');
		});
	};
	tips();
	setInterval(function() {
		rotate(rotateSymbol, ++count)
	},
	100);
})